<#
	#   It is recommended to test the script on a local machine for its purpose and effects. 
	#   Endpoint Central will not be responsible for any 
	#   damage/loss to the data/setup based on the behavior of the script.

	#   Description: Script to fetch Ram Details i.e) Ram Type, Total RAM, Available RAM, Used RAM
	#   Configuration Type - Computer
#>


# Get RAM details including type using PowerShell

# Get the type of RAM installed using SMBIOSMemoryType
$ramDetails = Get-WmiObject -Class Win32_PhysicalMemory
$ramTypes = @()

foreach ($ram in $ramDetails) {
    $ramType = switch ($ram.SMBIOSMemoryType) {
        0 {"Unknown"}
        1 {"Other"}
        2 {"DRAM"}
        3 {"Synchronous DRAM"}
        4 {"Cache DRAM"}
        5 {"EDO"}
        6 {"EDRAM"}
        7 {"VRAM"}
        8 {"SRAM"}
        9 {"RAM"}
        10 {"ROM"}
        11 {"Flash"}
        12 {"EEPROM"}
        13 {"FEPROM"}
        14 {"EPROM"}
        15 {"CDRAM"}
        16 {"3DRAM"}
        17 {"SDRAM"}
        18 {"SGRAM"}
        19 {"RDRAM"}
        20 {"DDR"}
        21 {"DDR2"}
        22 {"DDR2 FB-DIMM"}
        24 {"DDR3"}
        25 {"DDR3 SODIMM"}
        26 {"DDR4"}
        27 {"DDR4 SODIMM"}
        28 {"LPDDR"}
        29 {"LPDDR2"}
        30 {"LPDDR3"}
        31 {"LPDDR4"}
        Default {"Unknown"}
    }
    $ramTypes += $ramType
}

# Remove duplicate RAM types
$uniqueRamTypes = $ramTypes | Sort-Object -Unique

# Get total physical memory in bytes
$totalMemory = (Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory

# Convert bytes to gigabytes (GB)
$totalMemoryGB = [math]::Round($totalMemory / 1GB, 2)

# Get available physical memory in bytes
$availableMemory = (Get-WmiObject -Class Win32_OperatingSystem).FreePhysicalMemory

# Convert bytes to megabytes (MB) and then to gigabytes (GB)
$availableMemoryGB = [math]::Round($availableMemory / 1MB / 1024, 2)

# Calculate used physical memory
$usedMemoryGB = $totalMemoryGB - $availableMemoryGB

# Display RAM details
Write-Host "RAM Type: $($uniqueRamTypes -join ', ')"
Write-Host "Total RAM: $totalMemoryGB GB"
Write-Host "Available RAM: $availableMemoryGB GB"
Write-Host "Used RAM: $usedMemoryGB GB"